home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / PP Balloon Help Support / CBalloonDialog.cp < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.8 KB  |  136 lines  |  [TEXT/CWIE]

  1. // Source for CBalloonDialog class
  2.  
  3.  
  4. #include "CBalloonDialog.h"
  5. #include "CHelpAttach.h"
  6. #include "CMulberryApp.h"
  7.  
  8. #include <LListIterator.h>
  9. #include <LWindow.h>
  10. #include <UDrawingState.h>
  11.  
  12. // ===========================================================================
  13. //        • CBalloonDialog Class
  14. // ===========================================================================
  15.  
  16. // ---------------------------------------------------------------------------
  17. //        • CBalloonDialog
  18. // ---------------------------------------------------------------------------
  19. //    Constructor
  20.  
  21. CBalloonDialog::CBalloonDialog(ResIDT inDialogResID, LCommander    *inSuper)
  22.     : StDialogHandler(inDialogResID, inSuper)
  23. {
  24.     // Force application's periodics off
  25.     CMulberryApp::sApp->ErrorPause(true);
  26. }
  27.  
  28.  
  29. // ---------------------------------------------------------------------------
  30. //        • ~CBalloonDialog
  31. // ---------------------------------------------------------------------------
  32. //    Destructor
  33.  
  34. CBalloonDialog::~CBalloonDialog()
  35. {
  36.     // Force application's periodics on
  37.     CMulberryApp::sApp->ErrorPause(false);
  38. }
  39.  
  40. // Handle cursor motion for help balloons
  41. void CBalloonDialog::AdjustCursor(
  42.     const EventRecord    &inMacEvent)
  43. {
  44.                                     // Find out where the mouse is
  45.     WindowPtr    macWindowP;
  46.     Point        globalMouse = inMacEvent.where;
  47.     Int16        thePart = ::FindWindow(globalMouse, &macWindowP);
  48.     
  49.     Boolean        useArrow = true;    // Assume cursor will be the Arrow
  50.     
  51.     if (macWindowP != nil) {        // Mouse is inside a Window
  52.  
  53.         LWindow    *theWindow = LWindow::FetchWindowObject(macWindowP);
  54.         if ((theWindow != nil) &&
  55.             theWindow->IsActive() &&
  56.             theWindow->IsEnabled()) {
  57.                                     // Mouse is inside an active and enabled
  58.                                     //   PowerPlant Window. Let the Window
  59.                                     //   adjust the cursor shape.
  60.                                     
  61.                                     // Get mouse location in Port coords
  62.             Point    portMouse = globalMouse;
  63.             theWindow->GlobalToPortPoint(portMouse);
  64.             
  65.             theWindow->AdjustCursor(portMouse, inMacEvent);
  66.             useArrow = false;
  67.  
  68. // ----------------
  69. // Start of my bit
  70. // ----------------            
  71.             // Find the top pane under the mouse
  72.             LPane* hitPane = GetPaneUnderMouse(theWindow, portMouse.h, portMouse.v);
  73.  
  74.             // Execute the CHelpAttach if the pane exists
  75.             if (hitPane)
  76.                 hitPane->ExecuteAttachments(msg_ShowHelp, (void*) hitPane);
  77. // ----------------
  78. // End of my bit
  79. // ----------------            
  80.         }
  81.     }
  82.     
  83.     if (useArrow) {                    // Window didn't set the cursor
  84.                                     // Default cursor is the arrow            
  85.         SetCursor(&UQDGlobals::GetQDGlobals()->arrow);
  86.     }    
  87.     
  88.         // Rather than trying to calculate an accurate mouse region,
  89.         // we define a region that contains just the one pixel where
  90.         // the mouse is located. This is quick, and handles the common
  91.         // case where this application is in the foreground but the user
  92.         // isn't doing anything. However, any mouse movement will generate
  93.         // a mouse-moved event.
  94.         
  95.     ::SetRectRgn(mMouseRgnH, globalMouse.h, globalMouse.v,
  96.                              globalMouse.h + 1, globalMouse.v + 1);
  97. }
  98.  
  99. // Find the pane currently under the mouse
  100. LPane* CBalloonDialog::GetPaneUnderMouse(
  101.     LPane*        inPane,
  102.     Int32        inHorizPort,
  103.     Int32        inVertPort)
  104. {
  105. #if 0
  106.     LPane    *hitSubPane = nil;
  107.  
  108.     // Does this pane provide a hit?
  109.     if (!inPane->FindShallowSubPaneContaining(inHorizPort, inVertPort))
  110.     
  111.         // No hit => return this pane
  112.         return inPane;
  113.  
  114.     // If there was a hit then we know that inPane is in fact a LView so
  115.     // we can cast to get subpane list
  116.     
  117.     // Loop over all subpanes to find the first visible pane hit
  118.     LListIterator iterator(((LView*) inPane)->GetSubPanes(), iterate_FromEnd);
  119.     LPane    *theSub;
  120.     
  121.     while (iterator.Previous(&theSub)) {
  122.         if (theSub->Contains(inHorizPort, inVertPort) && theSub->IsVisible()) {
  123.             hitSubPane = GetPaneUnderMouse(theSub, inHorizPort, inVertPort);
  124.             if (hitSubPane == nil) {
  125.                 hitSubPane = theSub;
  126.             }
  127.             break;
  128.         }
  129.     }
  130.     
  131.     return hitSubPane;
  132. #else
  133.     return inPane->FindDeepSubPaneContaining(inHorizPort, inVertPort);
  134. #endif
  135. }
  136.